from typing import List, Optional, Dict, Any
from pydantic import BaseModel


# types
class UserVO(BaseModel):
    username: str
    password: str


class PublishVO(BaseModel):
    version: str


class PrivateCRUDVO(BaseModel):
    crud: Dict[str, Any]
    offset: Optional[float] = None


class DatasetVO(BaseModel):
    name: str
    owner: str
    collaborators: List[str] = []  # 合作者
    description: Optional[str] = ''
    is_public: bool = False  # 是否公有
    version_id: int = 0
    # last_update: str


class HostVO(BaseModel):
    dataset_name: str  # 属于哪个dataset
    name: str
    description: Optional[str] = ''
    host_ip: Optional[str] = ''
    offset: Optional[float] = None  # 与中央数据库的偏移量，可能不存在


class SourceVO(BaseModel):
    dataset_name: str  # 属于哪个dataset
    host_name: str  # 属于哪个host
    name: str
    description: Optional[str] = ''
    # last_update: str


class ColumnVO(BaseModel):
    dataset_name: str  # 属于哪个dataset
    host_name: str  # 属于哪个host
    source_name: str  # 属于哪个source
    name: str
    type: str  # 'string'|'number'|'bool'|'int'
    annotation: str  # 'start'|'end'|'edge'


class ResponseVO:
    # 状态码
    # 待添加的实体已存在：202 accept
    # 服务端异常：500
    code: int
    msg: str  # 消息

    def __init__(self, code, msg):
        self.code = code
        self.msg = msg
